package com.chen.qmzy.service;

import com.chen.qmzy.dao.DwUserDao;
import com.chen.qmzy.entity.DwUserEntity;
import com.chen.qmzy.entity.ResultEntity;
import jakarta.annotation.Resource;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;

@Service
public class DwUserService {
    private static final Logger logger= LoggerFactory.getLogger(DwUserService.class);//日志getLogger需要传入的类名
    @Resource
    DwUserDao dwUserDao;

    /**
     * 根据id获取用户详情
     * @param id 用户id
     * @return String
     */
    public DwUserEntity getDwUserList(int id){
        try{
            return dwUserDao.getDwUserList(id);
        }catch (Exception e){
            logger.error(e.getLocalizedMessage());
            return null;
        }
    }



    /**
     * 添加用户
     * @param uname 用户名称
     * @param password 密码
     * @param phone 电话
     * @param gender 性别
     * @param nickName 昵称
     * @param remark 注释
     * @return
     */
    public String addDwUser(String uname,String password,String phone,String email,int gender,String nickName,String remark){
        try{
            return ResultEntity.success(dwUserDao.addDwUser(uname,password,phone,email,gender,nickName,remark));
        }catch (Exception e){
            logger.error(e.getLocalizedMessage());
            return  ResultEntity.fail(-10005);
        }
    }

    /**
     * 重置头像
     * @param id id
     * @param avatar 地址
     */
    public String addAvatar(int id,String avatar){
        try{
            return ResultEntity.success(dwUserDao.addAvatar(id, avatar));
        }catch (Exception e){
            logger.error(e.getLocalizedMessage());
            return  ResultEntity.fail(-10005);
        }
    }


    /**
     * 登录
     * @param uname 用户名
     * @param password 密码
     * @return
     */
    public DwUserEntity login(String uname, String password){
        try{
           return dwUserDao.login(uname,password);
        }catch (Exception e){
            logger.error(e.getLocalizedMessage());
            return  null;
        }
    }

    /**
     *根据名称查询
     */
    public  String selectByName(String uname){
        try{
            return ResultEntity.success(dwUserDao.selectByName(uname));
        }catch (Exception e){
            logger.error(e.getLocalizedMessage());
            return ResultEntity.fail(-10005);
        }
    }

    /**
     * 修改用户信息
     */
    public boolean update(String uname,String email,String phone,int gender,String nickName,int id){
        try{
            return dwUserDao.update(uname, email, phone, gender, nickName, id);
        }catch (Exception e){
            logger.error(e.getLocalizedMessage());
            return true;
        }
    }

    public boolean updatapwd(int userId,String password){
        try{
            return dwUserDao.updatapwd(userId,password);
        }catch (Exception e){
            logger.error(e.getLocalizedMessage());
            return true;
        }
    }


}
